//*** Guidance generated code ***//
using System.Linq;
using System.Diagnostics.Contracts;
using System.Collections.Generic;
using System;

using Castle.DynamicProxy;

using Survey.Filters;

using ProjectBase.Core;

namespace Survey.Tools.IoC
{
    [Serializable]
    public class AopSelector : IInterceptorSelector
    {
        public IInterceptor[] SelectInterceptors(Type type, System.Reflection.MethodInfo method, IInterceptor[] interceptors)
        {
            IEnumerable<IInterceptor> list = interceptors;

            // Filter Restriction
            var isFacadeAndMethodBindFilter = method.Name.IsEqual("BindFilter")
                && type.GetInterfaces().Any(i => i.IsEquivalentTo(typeof(IFacade)));

            if (!isFacadeAndMethodBindFilter)
            {
                // Remove for any but IFacade's BindFilter operation
                list = list.Where(i => !(i is FilterRestrictionManager));
            }

            return list.ToArray();
        }
    }
}